import { getSlider } from '../api/public';
import WS from '@/utils/websocket'
import * as types from './action-types'; // 存放所有方法的类型，
const rootModule = {
    state: {
        sliders: [],
        ws: null,
        message: ''
    },
    mutations: {
        [types.SET_SLIDERS] (state, payload) {
            state.sliders = payload
        },
        [types.CREATE_WEBSOCKET] (state, ws) { // 存放ws信息
            state.ws = ws
        },
        [types.SET_MESSAGE] (state, msg) { // 存放msg信息
            state.message = msg
        }
    },
    actions: {
        // 调用getSlider()的api
        async [types.SET_SLIDERS] ({ commit }) {
            const { data } = await getSlider();
            console.log(data)
            commit(types.SET_SLIDERS, data)
        },
        async [types.CREATE_WEBSOCKET] ({ commit }) {
            let ws = new WS();
            ws.create(); // 调用src/utils/websocket.js中create的方法
            commit(types.CREATE_WEBSOCKET, ws);
        }
    },
    modules: {
    }
}
export default rootModule
